<?php
session_start();
$page = 'add_app';
error_reporting(0);
include 'connect/connect.php';
include_once 'header.php';
include('Includes/FusionCharts_Gen.php');
?>

<a href="add_app.php">&LT;&LT;  Back to applications</a> <a href="allUsage.php" class="button" style="float: left">Compare with your other applications  </a>
<?php
extract($_POST);
if (isset($_GET['appId'])) {
    $tid = $_GET['appId'];
}
//$added_by = $_SESSION['username'];
$FC = new FusionCharts("MSLine", "800", "500");

$FC->setSWFPath("Flash/");
$strParam = "caption=Application Usage;subcaption=Comparison;xAxisName=Week;yAxisName=Times Used;decimalPrecision=0";
$FC->setChartParams($strParam);
//no. of unique users
$users = "SELECT  count(DISTINCT user_id) as users
        FROM app_usage where app_id='$tid'";
$usersRe = mysql_query($users) or die("Error executing '$users':" . mysql_error());
if (mysql_num_rows($usersRe) > 0) {
    $rowRe = mysql_fetch_assoc($usersRe);
    extract($rowRe);
    echo "Total No. of Users = " . $users;
}


$query = "SELECT year(date_accessed),month(date_accessed),week(date_accessed), count(*)as time_accessed
        FROM app_usage where app_id='$tid' GROUP BY year(date_accessed), month(date_accessed),week(date_accessed)order by year(date_accessed)desc,week(date_accessed)desc";
$result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
if (mysql_num_rows($result) > 0) {
    $i = 1;
    while ($row = mysql_fetch_assoc($result)) {
        extract($row);
        $FC->addCategory("week " . $i);
//      $FC->addDataset($i);
        $FC->addChartData($time_accessed);
        $i++;
    }
}

$FC->renderChart();
?>

<?php include_once 'footer.php';?>